package com.hometeacher.api.controller;

import com.alibaba.fastjson.JSONObject;
import com.hometeacher.api.annoation.UserLoginToken;
import com.hometeacher.api.model.StuList;
import com.hometeacher.api.model.User;
import com.hometeacher.api.service.StudentService;
import com.hometeacher.api.util.Json;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.LinkedHashMap;

/**
 * @author ZhaoYuan
 * @data 04/04/2020 20:13
 */
@CrossOrigin
@RestController
@RequestMapping(value = "/student",method = RequestMethod.GET)
@Slf4j
public class StudentController {
    @Autowired
    private StudentService studentService;

    @Autowired
    private Json json;

//    @UserLoginToken
    @GetMapping(value = "allInfo")
    public LinkedHashMap<String, Object> getAllBaseInfo(){
        return json.getJson("studentList",studentService.findAllStudentInfo());
    }

    @PostMapping(value = "/change")
    public  Object change(@RequestBody StuList stuList){
        JSONObject jsonObject = new JSONObject();
        StuList StuListForBase = studentService.save(stuList);
        if (StuListForBase == null){
            jsonObject.put("message","error");
        } else {
            jsonObject.put("message","ok");
        }
        return jsonObject;
    }



}
